package com.yzpass.api.user.controller;

import com.yzpass.api.common.Constant;
import com.yzpass.api.common.FilterDTO;
import com.yzpass.api.common.IdName;
import com.yzpass.api.common.Result;
import com.yzpass.api.user.dto.RoleDTO;
import com.yzpass.api.user.entity.Role;
import com.yzpass.api.user.service.RoleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping(value = Constant.API + "role")
public class RoleController {
    @Resource
    RoleService roleService;

    @GetMapping("init")
    public Result<Role> init() {
        Role role = new Role();
        role.setRoleId(UUID.randomUUID());
        return Result.success(role);
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") String id) {
        return roleService.delete(id);
    }

    @PostMapping("save")
    public Result<RoleDTO> save(@RequestBody RoleDTO input) {
        return roleService.save(input);
    }

    @GetMapping("view/{id}")
    public Result<RoleDTO> view(@PathVariable("id") String id) {
        return roleService.view(id);
    }

    @PostMapping("list")
    public Result<List<RoleDTO>> list(@RequestBody FilterDTO input) {
        return roleService.list(input);
    }

    @GetMapping("simpleList")
    public Result<List<IdName>> simpleList() {
        return roleService.simpleList();
    }
}

